package com.zheng.utils.xmlUtil;

import java.util.*;
import java.util.Map.Entry;

public class SearchMapByKey {
	public static void main(String [] args){
		Map map = new HashMap();
		map.put("apple", "新鲜的苹果");
		map.put("computer", "配置优良的计算机");
		map.put("book", "堆积成山的图书");
		map.put("time", new Date()); 
		String key = "computer"; 
		Map map2 = new HashMap();
		map2.put("map", map);
		Map map3 = new HashMap();
		map3.put("map", map2);
		map3.put("test", "aaa");
		
		System.err.println(get(map3,"time"));
	}
	static Object obj;
	public static Object get(Map map,String byKey){
		obj = null;
		getdep(map,byKey);
		return obj;
	}
	
	public static void getdep (Map map,String byKey) {
		Iterator it = map.entrySet().iterator();
		while (it.hasNext()) {
			Entry entry = (Entry) it.next();
			Object val = entry.getValue();
			Object key = entry.getKey();
			if(key.equals(byKey)){
				obj = val;
				break;
			}
			if (val instanceof  Map) {
				getdep((Map)val,byKey);
			} 
			if(val instanceof ArrayList){
				List list = (ArrayList) val;
				for(int i=0;i<list.size();i++){
					getdep((Map) list.get(i),byKey);
				}
			}
		}
	}
	
}
